package com.ruoyi.product.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.product.domain.ProductSpecTemplate;
import com.ruoyi.product.service.IProductSpecTemplateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 规格属性模板Controller
 * 
 * @author liuhuizhong
 * @date 2025-08-07
 */
@RestController
@RequestMapping("/product/productSpecTemplate")
public class ProductSpecTemplateController extends BaseController
{
    @Autowired
    private IProductSpecTemplateService productSpecTemplateService;

    /**
     * 查询规格属性模板列表
     */
    @PreAuthorize("@ss.hasPermi('product:productSpecTemplate:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductSpecTemplate productSpecTemplate)
    {
        startPage();
        List<ProductSpecTemplate> list = productSpecTemplateService.selectProductSpecTemplateList(productSpecTemplate);
        return getDataTable(list);
    }

    /**
     * 导出规格属性模板列表
     */
    @PreAuthorize("@ss.hasPermi('product:productSpecTemplate:export')")
    @Log(title = "规格属性模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductSpecTemplate productSpecTemplate)
    {
        List<ProductSpecTemplate> list = productSpecTemplateService.selectProductSpecTemplateList(productSpecTemplate);
        ExcelUtil<ProductSpecTemplate> util = new ExcelUtil<ProductSpecTemplate>(ProductSpecTemplate.class);
        util.exportExcel(response, list, "规格属性模板数据");
    }

    /**
     * 获取规格属性模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:productSpecTemplate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(productSpecTemplateService.selectProductSpecTemplateById(id));
    }

    /**
     * 新增规格属性模板
     */
    @PreAuthorize("@ss.hasPermi('product:productSpecTemplate:add')")
    @Log(title = "规格属性模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductSpecTemplate productSpecTemplate)
    {
        return toAjax(productSpecTemplateService.insertProductSpecTemplate(productSpecTemplate));
    }

    /**
     * 修改规格属性模板
     */
    @PreAuthorize("@ss.hasPermi('product:productSpecTemplate:edit')")
    @Log(title = "规格属性模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductSpecTemplate productSpecTemplate)
    {
        return toAjax(productSpecTemplateService.updateProductSpecTemplate(productSpecTemplate));
    }

    /**
     * 删除规格属性模板
     */
    @PreAuthorize("@ss.hasPermi('product:productSpecTemplate:remove')")
    @Log(title = "规格属性模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(productSpecTemplateService.deleteProductSpecTemplateByIds(ids));
    }
}
